package com.cmfi.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.cmfi.domain.BOM;

// TODO 添加@Mapper
@Mapper
public interface BOMDao {
    @Insert("insert into tbl_bom (roleId,path) values(#{roleId},#{path})")
    public int save(BOM bom);
    
    @Update("update tbl_bom set roleId = #{roleId}, path = #{path} where id = #{id}")
    public int update(BOM bom);
    
    @Delete("delete from tbl_bom where id = #{id}")
    public int delete(Long id);
    
    @Select("select * from tbl_bom where id = #{id}")
    public BOM getById(Long id);
    
    @Select("select count(1) from tbl_bom")
	Long count();
    
    @Select("select * from  tbl_bom order by id DESC limit #{start},#{itemNum}")
	List<BOM> findByPage(long start, long itemNum);
    
    @Select("select * from  tbl_bom where id=#{id}")
    BOM findById(Long id);
    
    @Select("select tbl_user_role.roleId from tbl_user join tbl_user_role on tbl_user.id=tbl_user_role.userId where tbl_user.id = #{id}")
    public long findRoleId(Long id);
    
    @Select("select tbl_bom.path from tbl_bom where tbl_bom.roleId = #{roleId}")
	List<BOM> findByUser(long roleId);

    @Select("select * from  tbl_bom order by id DESC")
	public List<BOM> findAllBOMs();
}
